import {Component, OnInit} from '@angular/core';
import {UserInfo} from "../../modals/basic.modal";
import {BasicService} from "../../unit/basic-service";
import {Router} from "@angular/router";

@Component({
    selector: 'app-search-user',
    templateUrl: './search-user.page.html',
    styleUrls: ['../certificate-list/certificate-list.page.scss', './search-user.page.scss'],
})
export class SearchUserPage implements OnInit {
    searchList: Array<UserInfo>;
    warningText: string;

    constructor(
        private route: Router,
        private basicService: BasicService
    ) {
    }

    ngOnInit() {
        this.searchList = [];
    }

    searchData(e = '') {
        // search list date
        this.searchList = [];
        this.warningText = '';
        this.basicService.getData('yh/getyh', {name: e}).subscribe(res => {
            this.reGroupData(res);
        })
    }

    reGroupData(list) {
        if (!list || list.length < 1) {
            this.warningText = '暂无当前搜索数据';
        }
        this.searchList = [...list];
    }

    goToPage(url, item) {
        this.route.navigate([`/${url}`], {queryParams: {...item, urlType: 2}}).then();
    }

}
